﻿using System;
using System.Collections.Generic;
using System.Xml;

namespace T.SF.Console
{
    public class MiddlewareHandler : System.Configuration.IConfigurationSectionHandler
    {
        public object Create(object parent, object configContext, XmlNode section)
        {
            var configs = new List<MiddlewareConfig>();

            //获取配置文件中自定义节点值 
            foreach (XmlNode childNode in section.ChildNodes)
            {
                string name = null;
                var config = new MiddlewareConfig();
                if (childNode.Attributes["name"] != null)
                {
                    name = childNode.Attributes["name"].Value;
                    config.name = name;

                    if (childNode.Attributes["type"] != null)
                    {
                        config.type = Convert.ToString(childNode.Attributes["type"].Value);
                    }
                    if (childNode.Attributes["verb"] != null)
                    {
                        config.verb = Convert.ToString(childNode.Attributes["verb"].Value);
                    }
                    if (childNode.Attributes["path"] != null)
                    {
                        config.path = Convert.ToString(childNode.Attributes["path"].Value);
                    }

                    configs.Add(config);
                }
            }

            return configs;
        }
    }
}
